import { req,req_test } from '@/common/lib/request.js'
import { alert,alert_err,nav } from '@/common/lib/f.js'


const api = {}

api.req = (url,data,type,loading,method) => req(url,data,type,loading,method)
api.yzm = sjh => req(`front/sms/yzm/${sjh}`)
api.test = _ => req_test()

var url = "http://ydd.tysso.cn/api/ht/index.php/slmm_zz2/jspay?sign=b91dp0jGjiX1FOMka3Dc8f03y5dnmYxzQVMEN2LpxSbCGqpTFTu%2F5aAR4lbjHHPMkd3HU0B%2FZBYtKixFtQMtug%2BGOfa5u%2BNdaPp0wt8ErORwTjqWWQje6tfLMgihiMuhdkhiSYY%2BBJKcqjF9ZzqnA3Td1TfbW9Fl%2FrvUNoesSnRDAUUxAhHei6AnINo4sw";
api.getsign = _ => req(url)

api.zf = djbh => {
    var urls = window.location.href.substr(0,window.location.href.lastIndexOf('#')) + '#/pages/zf/re';
    api.req(`front/slmm/zfurl/${djbh}`,{
        url: urls
    }).then(res => {
        if (res.ok == 1) {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                window.location.href = res.urls;
            } else {
                nav('/pages/zf/re')
            }
        } else {
            alert_err(res)
        }
    })
}

api.zf2 = (djbh,data) => {
    // var urls = window.location.href.substr(0, window.location.href.lastIndexOf('#')) + '#/pages/zf/re';
    var urls = window.location.href.substr(0,window.location.href.lastIndexOf('#')) + `#/pages/zf/zfload?djbh=${djbh}`;
    api.req(`front/slmm/zfurl2/${djbh}`,{
        url: urls,...data
    }).then(res => {
        if (res.ok == 1) {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                window.location.href = res.urls;
            } else {
                nav('/pages/zf/re')
            }
        } else {
            alert_err(res)
        }
    })
}

api.ast = (djbh) => {
    // var urls = window.location.href.substr(0, window.location.href.lastIndexOf('#')) + `#/pages/zf/zfload?res=${djbh}`;
    var urls = window.location.href.substr(0,window.location.href.lastIndexOf('#')) + '#/pages/zf/re';
    api.req(`front/slmm/authaccesstoken/${djbh}`,{
        url: urls
    }).then(res => {
        // console.log(res.urls);
        if (res.ok == 1) {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                window.location.href = res.urls;
            } else {
                alert(res.urls)
                // nav('/pages/zf/re')
            }
        } else {
            alert_err(res)
        }
    })
}

// ========== 商品浏览历史相关API ==========

// 获取商品浏览历史分页列表
api.getBrowseHistoryPage = (params) => {
    return req('/app-api/product/browse-history/page', {
        pageNo: params.pageNo || 1,
        pageSize: params.pageSize || 10,
        createTime: params.createTime || null
    }, 'GET', 'json', true)
}

// 删除指定商品的浏览历史
api.deleteBrowseHistory = (spuIds) => {
    return req('/app-api/product/browse-history/delete', {
        spuIds: spuIds
    }, 'DELETE', 'json', true)
}

// 清空所有浏览历史
api.cleanBrowseHistory = () => {
    return req('/app-api/product/browse-history/clean', {}, 'DELETE', 'json', true)
}

// ========== 婚恋相关API ==========

// 获取婚恋会员分页列表
api.getDatingMemberPage = (params) => {
    return req('/dating/member/page', {
        pageNo: params.pageNo || 1,
        pageSize: params.pageSize || 10,
        queryType: params.queryType || 'index',
        sex: params.sex || null,
        excludeMyId: params.excludeMyId || null
    }, 'GET', 'json', true)
}

// 获取婚恋会员详情
api.getDatingMember = (userId) => {
    return req('/dating/member/get', {
        userId: userId
    }, 'GET', 'json', true)
}

// 获取最近来访列表（基于PV排序的会员列表）
api.getRecentVisitors = (params) => {
    return req('/dating/member/page', {
        pageNo: params.pageNo || 1,
        pageSize: params.pageSize || 20,
        queryType: 'recent', // 自定义查询类型
        orderBy: 'pv', // 按浏览量排序
        orderDirection: 'desc' // 降序
    }, 'GET', 'json', true)
}

// 婚恋关系操作（点赞、收藏等）
api.datingRelative = (data) => {
    return req('/dating/member/relative', data, 'POST', 'json', true)
}

// 获取关系列表（点赞、收藏等）
api.getDatingRelativeList = (params) => {
    return req('/dating/member/relative/page', {
        pageNo: params.pageNo || 1,
        pageSize: params.pageSize || 10,
        type: params.type // 1点赞 2收藏
    }, 'GET', 'json', true)
}

// ========== 活动相关API ==========

// 获取活动列表
api.getActivityList = () => {
    return req('/station/activity/list', {}, 'GET', 'json', true)
}

// 获取活动详情
api.getActivityDetail = (activityId) => {
    return req('/station/activity/get', {
        id: activityId
    }, 'GET', 'json', true)
}

// 报名参加活动
api.registerActivity = (activityId) => {
    return req('/station/activity/register', {
        id: activityId
    }, 'POST', 'json', true)
}

// 获取用户已加入的组织列表
api.getUserOrganizations = () => {
    return req('/station/member/organizations', {}, 'GET', 'json', true)
}

// 获取用户已报名的活动列表
api.getUserRegisteredActivities = () => {
    return req('/station/activity-registration/my-activities', {}, 'GET', 'json', true)
}

// ========== 退款相关API ==========

// 创建退款申请
api.createRefund = (data) => {
    return req('/trade/after-sale/create', data, 'POST', 'json', true)
}

// 获取退款列表
api.getRefundList = (params) => {
    return req('/trade/after-sale/page', {
        pageNo: params.pageNo || 1,
        pageSize: params.pageSize || 10
    }, 'GET', 'json', true)
}

// 获取退款详情
api.getRefundDetail = (id) => {
    return req(`/trade/after-sale/get?id=${id}`, {}, 'GET', 'json', true)
}

// 获取订单物流轨迹
api.getExpressTrackList = (orderId) => {
    return req(`/trade/order/get-express-track-list?id=${orderId}`, {}, 'GET', 'json', true)
}

// 获取订单详情
api.getOrderDetail = (id) => {
    return req(`/trade/order/get?id=${id}`, {}, 'GET', 'json', true)
}

// 获取订单项详情
api.getOrderItem = (id) => {
    return req(`/trade/order/item/get?id=${id}`, {}, 'GET', 'json', true)
}

// 创建订单项评价
api.createOrderItemComment = (data) => {
    return req('/trade/order/item/create-comment', data, 'POST', 'json', true)
}

// 取消退款申请
api.cancelRefund = (id) => {
    return req(`/trade/after-sale/cancel?id=${id}`, {}, 'DELETE', 'json', true)
}


export default api

// ***************************************************************************
// 使用方法 main.js 引入
// import api from '@/common/api/index.js'
// Vue.prototype.$api = api;

// this.$api.yzm(sjh).then(res => {
// 	console.log(res) // 获得数据
//  }).catch(res => {
// 	console.log(res) // 失败进行的操作
//  })
// ***************************************************************************




// import * as api from '@/common/api/index.js'
// this.$a.test('core/login/test',{}).then(res => {
// 	console.log(res) // 获得数据
//  }).catch(res => {
// 	console.log(res) // 失败进行的操作
//  })

// this.$a.test2({}).then(res => {
// 	console.log(res) // 获得数据
//  }).catch(res => {
// 	console.log(res) // 失败进行的操作
//  })